package com.hxzy.common.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * @author nick
 */
@Getter
@Setter
@ApiModel(description = "返回结果对象")
public class ResultVO<T> {
    @ApiModelProperty(value = "消息编码")
    private Integer code;
    @ApiModelProperty(value = "消息内容")
    private String message;
    @ApiModelProperty(value = "数据")
    private T data;


    //为了防止用户乱new
    private ResultVO(){

    }

    public static ResultVO  success(){
        return  success(ResultEnum.OK);

    }

    public static ResultVO  success(ResultEnum resultEnum){
        ResultVO  resultVO=new ResultVO();
        resultVO.setCode(resultEnum.getCode());
        resultVO.setMessage(resultEnum.getMessage());
        return resultVO;
    }

    public static ResultVO  success(ResultEnum resultEnum,Object data){
       ResultVO  resultVO=success(resultEnum);
       resultVO.setData(data);
        return resultVO;
    }

    public static ResultVO  success(Object data){
        return success(ResultEnum.OK, data);
    }

    public static ResultVO  failed(ResultEnum resultEnum){
        ResultVO  resultVO=new ResultVO();
        resultVO.setCode(resultEnum.getCode());
        resultVO.setMessage(resultEnum.getMessage());
        return resultVO;
    }

}
